package com.ss.android.topic.c;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.bytedance.article.common.c.JSONObjectWrapper;
import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.app.AppData;
import com.ss.android.common.lib.MobClickCombiner;

import org.json.JSONException;
import org.json.JSONObject;

public class a extends com.ss.android.topic.a.a {
    private long a;
    private long b;
    private long c;

    public a() {

    }

    public final JSONObject a() {
        JSONObject v2_1;
        JSONObject v0 = null;
        if(this.getIntent() == null) {
            v0 = new JSONObject();
            return v0;
        }

        Intent v0_1 = this.getIntent();
        String v2 = v0_1.getStringExtra("gd_ext_json");
        JSONObject v1 = null;
        try {
            if(!TextUtils.isEmpty(((CharSequence)v2))) {
                v0 = new JSONObject(v2);
                return v0;
            }

            v2_1 = new JSONObject();
            v2_1.put("enter_from", v0_1.getStringExtra("enter_from"));
            v0 = v2_1;
            if(v0 == null) {
                v0 = new JSONObject();
            }

            return v0;
        }
        catch(Exception v0_2) {
            if(Logger.debug()) {
                v0_2.printStackTrace();
            }
        }
        return new JSONObject();

    }

    public final void a(String arg5, JSONObject arg6) {
        String v1 = this.b();
        if(!android.support.design.a.isTextEmpty(arg5)) {
            String v0 = arg6.optString("category_name");
            if(!android.support.design.a.isTextEmpty(v1)) {
                if(v1.equals("click_" + v0)) {
                    v1 = "click_category";
                }
                else if(!v1.equals("click_headline")) {
                    v0 = v1.replaceFirst("click_", "");
                }
            }

            JSONObjectWrapper v0_1 = new JSONObjectWrapper().put("enter_from", v1).put("category_name", v0).put(arg6);
            if(AppData.getInstance().getAbSettings().isApplogStaging()) {
                v0_1.put("_staging_flag", Integer.valueOf(1));
            }

            android.support.design.a.onEvent(arg5, v0_1.jo);
        }
    }

    public final String b() {
        JSONObject v0 = this.a();
        String v0_1 = v0 != null ? v0.optString("enter_from", "unknown") : "unknown";
        return v0_1;
    }

    public String c() {
        return "unknown";
    }

    public long d() {
        return 0;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.a = System.currentTimeMillis();
    }

    public void onDestroy() {
        super.onDestroy();
        JSONObject v8 = this.a();
        long v10 = System.currentTimeMillis() - this.a;
        try {
            v8.put("ext_value2", v10);
        }
        catch(JSONException v0) {
        }

        MobClickCombiner.onEvent(this, this.c(), "stay_page", this.d(), this.c, v8);
        if(this.c > 3000) {
            if(AppData.getInstance().getAbSettings().isAppLogOld()) {
                MobClickCombiner.onEvent(this, "stay_page", this.b(), this.d(), this.c, v8);
            }

            if(!AppData.getInstance().getAbSettings().isAppLogNew()) {
                this.c = 0;
                return;
            }

            try {
                v8.remove("ext_value2");
                v8.put("stay_time2", v10);
                v8.put("qid", this.d());
                v8.put("stay_time", this.c);
                v8.put("group_id", this.d());
            }
            catch(JSONException v0) {
            }

            this.a("stay_page", v8);
        }

        this.c = 0;
    }

    public void onNewIntent(Intent arg10) {
        this.a = System.currentTimeMillis();
        MobClickCombiner.onEvent(this, this.c(), "enter", this.d(), 0, this.a());
        super.onNewIntent(arg10);
    }

    public void onPause() {
        super.onPause();
        this.c += System.currentTimeMillis() - this.b;
    }

    public void onResume() {
        super.onResume();
        this.b = System.currentTimeMillis();
    }
}

